package com.example.module_home.network

import com.example.module_home.Article
import com.example.module_home.ArticleData
import com.example.module_home.BaseResponse
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn

class Repository {

    companion object {
        fun getPost(): Flow<List<PostEntity>> = flow {
            RetrofitClient.api.fetchPost().apply {
                emit(this)
            }

        }.flowOn(Dispatchers.IO)


        fun getAlbum(): Flow<List<AlbumEntity>> = flow {
            val albums = RetrofitClient.api.fetchAlbum()
            emit(albums)
        }.flowOn(Dispatchers.IO)


        /* fun fetchArticle(page: Int = 0): Flow<List<Article>> = flow {
             val articleList = RetrofitClient.api.fetchArticle(page).data.datas
             emit(articleList)
         }.flowOn(Dispatchers.IO)*/

        suspend fun fetchArticle(page: Int ): BaseResponse<ArticleData>{
            return RetrofitClient.api.fetchArticle(page)
        }
    }

}